package com.njupt.towersutils.components;

import com.njupt.towersutils.domain.ManagersInfos;
import com.njupt.towersutils.mapper.ManagersInfosMapper;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MySQLToRedis {
    @Resource
    private ManagersInfosMapper managersInfosMapper;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Scheduled(cron = "0 13 18 * * ?")
    public void managersDataTransform(){
        System.out.println("start");
        //读取所有mysql数据库　managers数据 发送到redis数据库的managers hash中
        List<ManagersInfos> mis=managersInfosMapper.findAll();
        for(ManagersInfos mi:mis){
            stringRedisTemplate.opsForHash().put("managers",mi.getLoginname()+","+mi.getLoginpwd(),mi.toString());
        }
        System.out.println("final");


    }
}
